package com.hex.ds.hdrs.period.job.dto;

import cn.hutool.core.util.StrUtil;
import com.hex.ds.hdrs.common.constant.Const;
import com.hex.ds.hdrs.period.job.po.PeriodJobDef;
import com.hex.ds.hdrs.period.task.dto.PeriodTaskDefDto;
import lombok.Data;
import lombok.experimental.Accessors;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

@Data
@Accessors(chain = true)
public class PeriodJobDefDto {

    private String pkId;

    private String jobCode;

    private List<String> jobCodeList;

    private String jobName;

    private List<String> jobNameList;

    private String jobDesc;

    private String jobStatus;

    private String jobPeriod;

    private Integer sortNo;

    private Integer offsetHour;

    private String dateExpression;

    private String isValidDate;

    private String jobStDate;

    private String jobEndDate;

    private String batchTag;

    private String appCode;

    private String appName;

    private String appointAgentCode;

    private String crtUser;

    private String crtTs;

    private String upUser;

    private String upTs;

    private String isWorkRun;

    private String jobNameAndJobCode;

    private String isSingleJob;

    private String labelName;

    private List<String> labelJobCodeList;

    private String bizDate;

    private List<String> labelCodeList;

    /**
     * 导出主键集合
     */
    private List<String> pkIds;

    private String startTimeStart;

    private String startTimeEnd;

    private String endTimeStart;

    private String endTimeEnd;

    private List<String> selectionList;

    // 日期范围
    private String[] dateRange;

    private String labelCode;

    private String jobCodeFuzzy;

    private String jobNameFuzzy;

    private List<PeriodTaskDefDto> periodTaskDefDtoList = new ArrayList<>();

    public String getJobStDate() {
        if ("1".equals(isValidDate) && dateRange != null && dateRange.length == 2) {
            return dateRange[0];
        }else {
            return null;
        }
    }

    public String getJobEndDate() {
        if (Const.JOB_OPEN_VAILID_DATE.equals(isValidDate) && dateRange != null && dateRange.length == 2) {
            return dateRange[1];
        }else {
            return null;
        }
    }

    public String getIsValidDate() {
        if (StrUtil.isNotBlank(isValidDate)) {
            return isValidDate;
        } else if (dateRange != null && dateRange.length == 2) {
            return Const.JOB_OPEN_VAILID_DATE;
        } else {
            return Const.JOB_CLOSE_VAILID_DATE;
        }
    }

    public List<String> getLabelJobCodeList() {
        if (StrUtil.isNotBlank(labelCode)){
            return Arrays.asList(StrUtil.split(labelCode, ","));
        }
        return labelJobCodeList;
    }
}
